﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
using System.Windows.Markup;
using System.Globalization;

namespace WpfApp1.Controls
{

    [ContentProperty("Content")]
    public class CustomControl : Control
    {
        static CustomControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl)));
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            // 绘制一个简单的矩形
            drawingContext.DrawRectangle(Brushes.LightBlue, new Pen(Brushes.DarkBlue, 2), new Rect(0, 0, this.Width, this.Height));

            // 绘制文本
            drawingContext.DrawText(new FormattedText(Content,
                CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Arial"),
                16, Brushes.Black), new Point(10, 10));
        }


        public static readonly DependencyProperty ContentProperty =
           DependencyProperty.Register(
           "Content",
     typeof(string),
     typeof(CustomControl),
     new PropertyMetadata(default(string)));

        public string Content
        {
            get => (string)GetValue(ContentProperty);
            set => SetValue(ContentProperty, value);
        }
    }

   
}
